package com.example.gobang_system.dao.mapper;

import com.example.gobang_system.common.pojo.UserInfo;
import com.example.gobang_system.dao.dataobject.UserDO;
import org.apache.ibatis.annotations.*;

@Mapper
public interface UserMapper {
    @Insert("insert into user" +
            " (user_name, password, score, total_count, win_count) " +
            " values (#{userName}, #{password}, 1000, 0, 0)")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    int insert(UserDO userDO);

    @Select("select * from user where user_name = #{userName}")
    UserDO selectByUserName(@Param("userName") String userName);


    @Update("update user set total_count = total_count + 1, win_count = win_count + 1, score = score + 30 " +
            " where id = #{id}")
    int updateWinner(@Param("id") Long winner);

    @Update("update user set total_count = total_count + 1, score = score - 30 " +
            " where id = #{id}")
    int updateLoser(@Param("id") Long loser);

    @Select("select * from user where id = #{id}")
    UserDO selectByUserId(@Param("id") Long id);
}
